<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>home</title>



</head>
<body>
    <button id="Btn" data-pdf-id="1">下载 PDF</button>
    <button>你好</button>
    <script>
        document.getElementById('Btn').addEventListener('click', function() {
            const pdfId = this.getAttribute('data-pdf-id');
            console.log('正在尝试下载ID为:', pdfId, '的PDF文件');
            fetch(`http://localhost:8080/downloadPmc'+ pdfId)`
                .then(response => {
                    if (response.ok) {
                        return response.blob(); // 获取文件 Blob
                    }
                    throw new Error('Network response was not ok.');
                })
                .then(blob => {
                    const url = window.URL.createObjectURL(blob);
                    const a = document.createElement('a');
                    a.href = url;
                    a.download = 'filename.pdf'; // 设置下载文件的名称
                    document.body.appendChild(a);
                    a.click();
                    window.URL.revokeObjectURL(url); // 释放 URL 对象
                    document.body.removeChild(a);
                })
                .catch(error => {
                    console.error('There was a problem with the fetch operation:', error);
                });
        });
    </script>
</body>
</html>